<template>
  <div class="common-layout">
    <el-container class="home-container">
      <el-header>
        <div class="info-box">
          <img :src="userinfoData.userinfo.avatar" alt="" class="avatar" />
          <span class="username">{{ userinfoData.userinfo.username }}</span>
          <span class="uid"></span>
        </div>
        <el-button type="info" @click="handleLogout">退出登录</el-button>
      </el-header>
      <el-container>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup>
import { ElMessage } from 'element-plus'
import { useStore } from 'vuex'
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'

const store = useStore()

const router = useRouter()

const userinfoData = reactive({
  username: store.state.userinfo.username,
  userinfo: store.state.userinfo
})

const handleLogout = async () => {
  router.push('/login')
  return ElMessage({
    message: '退出成功',
    type: 'success',
  })
}

</script>

<style scoped>
.common-layout {
  height: 100%;
}

.el-container {
  overflow: auto;
}

.home-container {
  height: 100%;
}

.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #373d41;
  padding-left: 0;
  color: #fff;
  font-size: 20px;
}

.el-header > div {
  display: flex;
  align-items: center;
}

.el-header > div span {
  margin-left: 15px;
}

.avatar {
  height: 50px;
  width: 50px;
  margin-left: 20px;
  border-radius: 50%;
}
</style>
